package com.gongpingjialoan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gongpingjialoan.R;
import com.gongpingjialoan.bean.Domain;

import java.util.List;

/**
 * Created by Administrator on 2016/10/9.
 */
public class DomainAdapter extends BaseAdapter {
    private List<Domain> mDomains;
    private Context mContext;
    private LayoutInflater mLayoutInflater;

    public DomainAdapter(List<Domain> domains, Context context) {
        mDomains = domains;
        mContext = context;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mDomains.size();
    }

    @Override
    public Object getItem(int position) {
        return mDomains.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(R.layout.domain_item, null);
        }

        TextView nameT = (TextView) convertView.findViewById(R.id.name);
        ImageView imageView = (ImageView) convertView.findViewById(R.id.switch_id);

        if (mDomains.get(position).isCheck()) {
            imageView.setImageResource(R.drawable.checked);
        } else {
            imageView.setImageResource(R.drawable.uncheck);
        }
        nameT.setText(mDomains.get(position).getName());
        return convertView;
    }
}
